package mc

import (
	. "ez/apps/erp/auto/mc"
	"gitee.com/dreamwood/ez-go/db/mgo"
)

const (
	TdEventNew           = "td.TdNew"
	TdEventBeforeCreate  = "td.TdBeforeCreate"
	TdEventBeforeUpdate  = "td.TdBeforeUpdate"
	TdEventBeforeSave    = "td.TdBeforeCreate td.TdBeforeUpdate"
	TdEventAfterCreate   = "td.TdAfterCreate"
	TdEventAfterUpdate   = "td.TdAfterUpdate"
	TdEventAfterSave     = "td.TdAfterCreate td.TdAfterUpdate"
	TdEventDelete        = "td.TdDelete"
	TdAccessControlEvent = "td.TdAccessControl"
)

func GetTdConfig() *mgo.DocConfig {
	return Td_Config
}

var Td_Config *mgo.DocConfig

func init() {
	Td_Config = NewTdConfig()
}
func NewTdConfig() *mgo.DocConfig {
	return &mgo.DocConfig{
		ContainerKey: "td.Td",
		Fields: []string{
			"title", "content", "cat", "targetEmp", "createEmp", "auditEmp", "auditAt", "publishAt", "reads", "readEmps",
		},
		RelationFields: []string{
			"cat", "targetEmp", "createEmp", "auditEmp", "readEmps",
		},
		RelationConfigs: map[string]*mgo.DocRelation{
			"cat": {
				Config:     GetTdCategoryConfig,
				DocName:    "TdCategory",
				JoinType:   "O",
				KeyInside:  "catId",
				KeyOutSide: "id",
			},
			"targetEmp": {
				Config:     GetEmpConfig,
				DocName:    "Emp",
				JoinType:   "O",
				KeyInside:  "targetEmpId",
				KeyOutSide: "id",
			},
			"createEmp": {
				Config:     GetEmpConfig,
				DocName:    "Emp",
				JoinType:   "O",
				KeyInside:  "createEmpId",
				KeyOutSide: "id",
			},
			"auditEmp": {
				Config:     GetEmpConfig,
				DocName:    "Emp",
				JoinType:   "O",
				KeyInside:  "auditEmpId",
				KeyOutSide: "id",
			},
			"readEmps": {
				Config:     GetEmpConfig,
				DocName:    "Emp",
				JoinType:   "MM",
				KeyInside:  "readEmpsIds",
				KeyOutSide: "id",
			},
		},
		FieldFilter: map[string]*mgo.DocFieldFilter{
			"default": {
				Select: []string{},
				Omit:   []string{},
			},
		},
	}
}
